package com.qilu.pe.support.util;

import android.app.Activity;
import android.app.StatusBarManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.BarUtils;
import com.qilu.pe.R;

public class AlertUtil {
    public static void setAlertBottomInStyle(Window window, View alert_view, Activity activity) {
        window.setContentView(alert_view);
        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.DialogBottomStyle);//添加动画

        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = activity.getWindowManager().getDefaultDisplay().getWidth();
        window.setAttributes(layoutParams);
    }

    public static void setAlertRightInStyle(Window window, View alert_view, Activity activity) {
        window.setContentView(alert_view);
        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.DialogRightStyle);//添加动画

        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = activity.getWindowManager().getDefaultDisplay().getWidth();
        window.setAttributes(layoutParams);
    }

    public static void setAlertRightInStyleNoDim(Window window, View alert_view, Activity activity) {
        window.setContentView(alert_view);
        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.DialogRightStyle);//添加动画

        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        BarUtils.transparentStatusBar(window);
        BarUtils.setStatusBarLightMode(window, true);
        window.setAttributes(layoutParams);
    }

    public static void setAlertCenterStyle(Window window, View alert_view, Activity activity) {
        window.setContentView(alert_view);
        window.setGravity(Gravity.CENTER);  //此处可以设置dialog显示的位置
//        window.setWindowAnimations(R.style.DialogBottomStyle);//添加动画

        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = activity.getWindowManager().getDefaultDisplay().getWidth();
        window.setAttributes(layoutParams);
    }

    // 通用提醒弹窗
    public static void showComDialog(Activity activity, String msg, final OnAlertBtnClickListner listner) {
        final AlertDialog alert = new AlertDialog.Builder(activity, R.style.Dialog_FS).create();
        alert.show();
        View alert_view = View.inflate(activity, R.layout.layout_alert_com_alert, null);
        TextView tv_title = alert_view.findViewById(R.id.tv_title);
        tv_title.setText(msg);
        alert_view.findViewById(R.id.tv_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alert.dismiss();
                if (null != listner) {
                    listner.onCancelClick();
                }
            }
        });
        alert_view.findViewById(R.id.tv_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alert.dismiss();
                if (null != listner) {
                    listner.onConfirmClick();
                }
            }
        });

        AlertUtil.setAlertCenterStyle(alert.getWindow(), alert_view, activity);
    }

    public interface OnAlertBtnClickListner {
        void onConfirmClick();

        void onCancelClick();
    }
}
